package com.zlfund.cat.zjgsmk.controller;

import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zlfund.cat.zjgsmk.R;
import com.zlfund.cat.zjgsmk.bean.UserBean;
import com.zlfund.cat.zjgsmk.ui.base.ZApplication;
import com.zlfund.cat.zjgsmk.ui.user.LoginActivity;
import com.zlfund.cat.zjgsmk.ui.user.UserManager;
import com.zlfund.cat.zjgsmk.widget.HeadView;

/**
 * Created by chenj on 2017/9/21 0021.
 */

public abstract class LoginStateImp implements ILoginStateService {

    protected LinearLayout mLlFocusLlyt;
    protected LinearLayout mLlLoginShow;
    protected HeadView mHeadView;
    protected ImageView mIvUserIcon;
    protected TextView mTvName;
    protected TextView mTvDesc;
    protected TextView mTvFocus;
    protected TextView mTvFans;
    protected TextView mTvLogin;
    protected LinearLayout mLlytLogin;

    @Override
    public boolean hasLogin() {
        boolean isLogin = UserManager.isLogin();
        if (!isLogin){
            Intent intent = new Intent(ZApplication.mContext, LoginActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            ZApplication.mContext.startActivity(intent);
        }
        return isLogin;
    }

    @Override
    public String getAuthToken() {
        //获取token
        return UserManager.getAuth();
    }

    @Override
    public void showSquareUI(ViewGroup rootView) {
        mLlFocusLlyt = (LinearLayout) rootView.findViewById(R.id.ll_focus_topic);
    }

    @Override
    public void showSettingUI(ViewGroup rootView) {
        mLlLoginShow = (LinearLayout) rootView.findViewById(R.id.llyt_login_show);
        mLlytLogin = (LinearLayout) rootView.findViewById(R.id.llyt_exit_login);
        mTvLogin = (TextView) rootView.findViewById(R.id.tv_login);
    }

    @Override
    public void showUserUi(ViewGroup rootView, UserBean bean) {
        mHeadView = (HeadView) rootView.findViewById(R.id.headView);
        mIvUserIcon = (ImageView) rootView.findViewById(R.id.iv_icon);
        mTvName = (TextView) rootView.findViewById(R.id.tv_name);
        mTvDesc = (TextView) rootView.findViewById(R.id.tv_desc);
        mTvFocus = (TextView) rootView.findViewById(R.id.tv_focus);
        mTvFans = (TextView) rootView.findViewById(R.id.tv_fans);
        mIvUserIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                hasLogin();
            }
        });
    }
}
